package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         62,
		Discription: "从左上角到右下角的路径个数",
		Level:       2,
		Labels: map[string]int{
			"动态规划": 1,
			"空间复用": 1,
		},
	})
}

func UniquePaths(m int, n int) int {
	//到达每一列的路径个数，从第0行开始往下迭代
	//dp[j]=上一行（还未更新）的dp[j]+当前行（已更新）的dp[j-1]
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = 1
	}

	for i := 1; i < m; i++ {
		for j := 1; j < n; j++ {
			dp[j] += dp[j-1]
		}
	}

	return dp[n-1]
}
